﻿using System;
using System.Reflection;
using System.Windows.Forms;
using FastFood.Business.Entities;
using FastFood.Business.Logic;
using WeifenLuo.WinFormsUI.Docking;
using WindowsControls.VB.Office2007Renderer;

namespace FastFood.Windows.Paneles
{
    public partial class FrmDocumento : DockContent
    {
        bool cerrar;

        public FrmDocumento(Formularios formulario)
        {
            InitializeComponent();
            MenuCn menuCn = new MenuCn();
            if (DesignMode == false)
            {
                Menus padre = menuCn.ObtenerMenuPorID(formulario.menuID);
                string nombreNamespace;
                if (padre.carpeta.Equals("."))
                {
                    nombreNamespace = "FastFood.Windows.Informes";
                }
                else
                {
                    nombreNamespace = padre.carpeta;
                    while (padre.contenedorID != null)
                    {
                        padre = menuCn.ObtenerMenuPorID(padre.contenedorID.Value);
                        nombreNamespace = padre.carpeta + "." + nombreNamespace;
                    }
                    nombreNamespace = "FastFood.Windows.Forms." + nombreNamespace;
                }

                this.TabText = formulario.nombre;
                this.Text = formulario.nombreClase;
                this.cerrar = formulario.estado;
                Assembly asm = Assembly.GetExecutingAssembly();
                UserControl userControl = (UserControl)asm.CreateInstance(nombreNamespace + "." + formulario.nombreClase);
                if (userControl != null)
                {
                    userControl.BackColor = System.Drawing.Color.FromArgb(191, 219, 255);
                    userControl.Tag = formulario.formularioID;
                    userControl.Dock = DockStyle.Fill;
                    this.Controls.Add(userControl);

                }
            }
        }

        private void FrmDocumento_Load(object sender, EventArgs e)
        {
            ToolStripManager.Renderer = new Office2007Renderer();
        }

        private void mitCloseTab_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }
    }
}
